home *** CD-ROM | disk | FTP | other *** search
- Path: dakal.demon.co.uk!richardlh
- From: Richard Linsley Hood <richardlh@dakal.demon.co.uk>
- Newsgroups: comp.lang.c++,comp.lang.pascal.delphi.misc
- Subject: Re: C++ with Zapp vs. Delphi
- Date: Mon, 22 Jan 1996 19:48:21 +0000
- Organization: Dakal Systems Ltd
- Distribution: world
- Message-ID: <fukt+AAFo+AxEwc9@dakal.demon.co.uk>
- References: <4coar6$d4n@sun4.bham.ac.uk> <4coip7$69s@news1.usa.pipeline.com>
- <DBk8wg2yqjbB083yn@iaccess.za> <4d7pmb$48c8@tigger.cc.uic.edu>
- <4dk38h$gdr@merlin.delphi.com> <4dksp1$3d6c@tigger.cc.uic.edu>
- <30fe666e.3349285@130.15.126.54> <4dmjt8$6sv@crc-news.doc.ca>
- <30ff9519.1799465@130.15.126.54> <4doe07$4u8@crc-news.doc.ca>
- <30ffe557.16481026@130.15.126.54> <GK+N9LA3rQAxEwdx@dakal.demon.co.uk>
- <AUSTERN.96Jan22100904@isolde.mti.sgi.com>
- NNTP-Posting-Host: dakal.demon.co.uk
- X-NNTP-Posting-Host: dakal.demon.co.uk
- MIME-Version: 1.0
- X-Newsreader: Turnpike Version 1.10 <EdeHes6g1FnzvsX+Q8nYPyW0xw>
-
- In article <AUSTERN.96Jan22100904@isolde.mti.sgi.com>, Matt Austern
- <austern@isolde.mti.sgi.com> writes
-
- >In article <GK+N9LA3rQAxEwdx@dakal.demon.co.uk> Richard Linsley Hood
- ><richardlh@dakal.demon.co.uk> writes:
- >
- >> The method and order by which comparisons are done is determined by the
- >> list. This is quite reasonably part of its function. It 'knows' about
- >> which two items should be compared to determine which is larger,
- >> smaller, etc., thus it is part of its function.
- >>
- >> The comparison of two objects should be done by themselves, 'are you
- >> larger, smaller than this object' thus hiding from the list how this is
- >> done. Only an object 'knows' how it compares to another object (of the
- >> same type). This is quite reasonably a function of the object.
- >>
- >> Where is the problem?
- >
- >The problem is that I might want to have one list of employees
- >arranged alphabetically by last name, one list arranged alphabetically
- >by first name, another arranged by numerical value of the employee ID,
- >and another arranged chronologically by date of hire.
- >
- >For a nontrivial object (like an employee record), there are too many
- >reasonable choices for the comparison function. An object shouldn't
- >necessarily impose one choice on all of its clients.
-
- For a complex object, such as you describe, with a complex requirement
- for ordering in separate lists as stated I would do the following.
-
- Create a base class for 'anindex' containing a virtual item 'index' and
- a pointer to 'employee' (a friend class to 'employee' if required, else
- operating on public members of 'employee').
-
- Derive from the 'anindex' base class the required sub-classes that
- incorporate your designated sort requirements with actual 'index'
- properties of the correct type.
-
- Create one or more lists than contain the base class 'anindex'. Add
- 'anindex' items to the lists as required.
-
- Very simple class structure, with remarkably little effort, easily
- extendible and completely sufficient to meet your requirements.
-
- --
- Richard Linsley Hood | Poole, Dorset UK | email: richardlh@dakal.demon.co.uk
- "Programming is mirroring the world, inside a computer" Larry O'Brien 1991
-